package com.situ.day05;

import java.util.Scanner;

public class StudentManger {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量：");
		int count = scanner.nextInt();
		Student[] array = new Student[count];
		for (int i = 0; i < array.length; i++) {
			System.out.println("请输入学生的id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生的姓名：");
			String name = scanner.next();
			System.out.println("请输入学生的年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生的班级：");
			String className = scanner.next();
			// 每次循环构造一个学生对象
			Student student = new Student(id, name, age, className);
			// 将每次遍历生成的student对象放到数组对应下标的位置
			array[i] = student;
		}
		for (int i = 0; i < array.length; i++) {
			// System.out.println(array[i]);
			Student student = array[i];
			System.out.println(student);
		}
		while (true) {
			System.out.println("----------------------");
			System.out.println("根据id查找输入：1");
			System.out.println("根据名字查找输入：2");
			System.out.println("根据年龄查找输入：3");
			System.out.println("根据班级查找输入：4");
			System.out.println("退出程序：0");
			System.out.println("----------------------");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出程序");
				break;
			}

			switch (type) {
			case 1:// 根据id查找
				System.out.println("根据id搜索");
				int searchId = scanner.nextInt();
				// 查找数组里面学生的名字是不是有要和搜索的名字一样，
				// 1、如果有就打印当前学生的信息，
				// 2、如果搜索完了所有学生都没有找到，打印“没有该姓名的学生”
				boolean isSearchIdFound = false;
				for (int i = 0; i < array.length; i++) {
					Student student = array[i];
					if (student.getId() == searchId) {
						isSearchIdFound = true;
						System.out.println(student);
					}

				}
				if (isSearchIdFound == false) {
					System.out.println("没这个人");
				}
				break;
			case 2:// 根据名字查找
				System.out.println("根据名字搜索");
				String searchName = scanner.next();
				// 查找数组里面学生的名字是不是有要和搜索的名字一样，
				// 1、如果有就打印当前学生的信息，
				// 2、如果搜索完了所有学生都没有找到，打印“没有该姓名的学生”
				boolean isSearchNameFound = false;
				for (int i = 0; i < array.length; i++) {
					Student student = array[i];
					if (student.getName().equals(searchName)) {
						isSearchNameFound = true;
						System.out.println(student);
					}
				}
				if (isSearchNameFound == false) {
					System.out.println("没这个人");
				}
				break;
			case 3:// 根据名字查找
				System.out.println("根据年龄搜索");
				int searchAge = scanner.nextInt();
				boolean isSearchAgeFound = false;
				for (int i = 0; i < array.length; i++) {
					Student student = array[i];
					if (student.getAge() == searchAge) {
						isSearchAgeFound = true;
						System.out.println(student);
					}
				}
				if (isSearchAgeFound == false) {
					System.out.println("没这个人");
				}
				break;
			case 4:// 根据班级查找
				System.out.println("根据班级搜索");
				String searchClassName = scanner.next();
				boolean isSearchClassNameFound = false;
				for (int i = 0; i < array.length; i++) {
					Student student = array[i];
					if (student.getClassName().equals(searchClassName)) {
						isSearchClassNameFound = true;
						System.out.println(student);
					}
				}
				if (isSearchClassNameFound == false) {
					System.out.println("没这个人");
				}
				break;
			}
		}
	}
}
